# Maintainer: Frederic Wang <fred.wang@free.fr>

_realname=idna
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.4
pkgrel=2
pkgdesc='Internationalized Domain Names in Applications (mingw-w64)'
url='https://github.com/kjd/idna'
license=('BSD-like')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-flit-core")
_dtoken="d8/82/28a51052215014efc07feac7330ed758702fc0581347098a81699b5281cb"
source=("https://pypi.io/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4')

prepare() {
  rm -rf python-build-${MSYSTEM}
  cp -r ${_realname}-${pkgver} python-build-${MSYSTEM}
}

build() {
  msg "Python build for ${MSYSTEM}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  msg "Python install for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
